import Response from '../utils/response.js';

export default async (ctx, next) => {
  ctx.success = function(data, message) {
    ctx.body = Response.success(data, message);
  };

  ctx.error = function(message, code) {
    ctx.body = Response.error(message, code);
  };

  try {
    await next();
  } catch (err) {
    ctx.error(err.message, err.status || 500);
  }
}; 